package com.quark.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.quark.bo.Sekill;
import com.quark.service.SekillService;

@Controller
@RequestMapping("/sekill")
public class SekillController {
    private Logger log = LoggerFactory.getLogger(SekillController.class);
	
	@Autowired
	private SekillService sekillService;
	
	@RequestMapping(value = "/{id}",method = RequestMethod.GET)
	public String querySekillById(@PathVariable("id") Integer id,Model model){
		Sekill sekill = sekillService.querySekillById(id);
		model.addAttribute("sekill", sekill);
		return "sekill";
	}
	
	@RequestMapping(value = "/operation",method = RequestMethod.GET)
	public String insertAndDeleteSekill(){
		log.info("即增加--删除--秒杀商品");
		int addNum = sekillService.insertAndDeleteSekill(1);
		log.info("是否插入成功：" + addNum);
		return "sekill";
	}
	
	@RequestMapping(value = "/{pageNum}/{pageSize}/all",method = RequestMethod.GET)
	public String queryAllSekill(@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize,Model model){
		List<Sekill> sekillList = sekillService.queryAllSekill(pageNum, pageSize);
		model.addAttribute("SEKILL_LIST", sekillList);
		return "sekillList";
	}
	
	@RequestMapping(value = "/{pageNum}/{pageSize}/all/rest",method = RequestMethod.GET,
				produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public List<Sekill> queryAllSekillForRest(@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize){
		return sekillService.queryAllSekill(pageNum, pageSize);
	}
}